package org.test.thread;

/**
 * Created by Hy on 2018/7/24.
 */
public class ThreadTest2 extends Thread{
    private String val1;
    private String val2;
    @Override
    public void run() {
        val1 = "val1";
        val2 = "val2";
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadTest2 t2 = new ThreadTest2();
        t2.start();
        t2.join();//将线程由异步执行转为同步执行
        //在调用start()方法后就立即输出val1、val2，这里run方法还没有指定到val1和val2的赋值语句
        System.out.println(t2.val1);//null
        System.out.println(t2.val2);//null
//        while(t2.val1==null || t2.val2==null){
//            sleep(100);
//        }
//        System.out.println(t2.val1);//val1
//        System.out.println(t2.val2);//val2
    }
}
